/*
 * 品牌列表
 * @Author: ljb
 * @Date: 2018-03-27 17:53:05
 * @Last Modified by: ljb
 * @Last Modified time: 2018-09-26 18:07:36
 */
<style lang="less" rel="stylesheet/less" type="text/less" >
	.v-admin-product-brand-index {
		.thumb{
			display: inline-block;
			width: 80px;
			height: 80px;
			position: relative;
			margin: 10px;
		}
		.thumb > img {
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%,-50%);
			max-width: 100%;
			max-height: 100%;
			cursor: pointer;
		}
	}
</style>
<template>
	<div class="v-admin-product-brand-index">

		<Table
			:columns="columns"
			:loading="loading"
			:data="brands"
			:height="tableHeight()"
			border
			class="personal-scrollbar"
			@on-sort-change="sortable"/>

	</div>
</template>

<script>

import Button from 'iview/src/components/button';
import labelWidthMixin from 'src/views/mixins/labelWidthMixin';
import { computedTableHeight } from 'src/views/mixins/computedTableHeight';

export default {
	name: 'AdminBrandIndex',
	mixins: [labelWidthMixin, computedTableHeight],
	props: {
		loading: {
			type: Boolean,
			default() {
				return false;
			},
		},
		brands: {
			type: Array,
			default() {
				return [];
			},
		},
	},
	data() {
		return {
			columns: [
				{
					title: this.$t('brand.name'),
					key: 'name',
					align: 'center',
					render: (h, { row }) => <div> { row.name || '-' } </div>,
				},
				{
					title: this.$t('brand.url'),
					key: 'url',
					align: 'center',
					render: (h, { row }) => <div> { row.url || '-' } </div>,
				},
				{
					title: this.$t('brand.logo'),
					key: 'logo',
					align: 'center',
					render: (h, { row }) => {
						const img_thumb = row.logo ? <img src={ row.logo } alt="无"/> : '无';
						return (<div class="thumb">{img_thumb}</div>);
					},
				},
				{
					title: this.$t('common.created_at'),
					key: 'created_at',
					align: 'center',
					render: (h, { row }) => <div> { !row.created_at ? '-' : row.created_at } </div>,
				},
				{
					title: this.$t('common.operation'),
					align: 'center',
					render: (h, { row }) => (
						<div>
							<Button size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('edit', row); }} type="primary">
								{this.$t('common.edit')}
							</Button>
							<Button size="small" on-click={() => { this.$emit('delete', row.id); }} type="error">
								{this.$t('common.delete')}
							</Button>
						</div>),
				},
			],
		};
	},
	methods: {

		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {
				sort_column: param.key,

				sort_by: param.order.toLocaleUpperCase(),
			};

			this.$emit('sort', search_param);
		},

	},
};
</script>
